Shader

Object Hierarchy | 関連する C++クラス:Shader

継承

SIObject

ProjectItem

Shader

導入

v1.5

詳細

Shader オブジェクトは、オブジェクトの Render Tree 内のノードです。Render Tree の初期シェーダはSceneItem.AddMaterialを使用して作成することができ、追加シェーダはParameter.ConnectFromPresetおよびParameter.Connectを使用して作成および接続することができます。

Shader はDataSourceの一種です。

メソッド

AddCustomOp AddProperty AddScriptedOp AddScriptedOpFromFile
AddSharedTextureLayer AnimatedParameters2 BelongsToオペレータ CodePath
CodeText CreateTextureLayer EvaluateAt GetAllShaders
GetICEAttributeFromName GetPortDisplayName GetShaderContainer GetShaderInputType
GetShaderParameterTargets GetShaderParameterType HasRenderer IsA
IsAnimated2 IsClassOfオペレータ IsEqualToオペレータ IsKindOf
IsLockedオペレータ IsSelectedオペレータ LockOwners PutPortDisplayName
RemoveTextureLayer RendererOptionValue SetAsSelectedオペレータ SetCapabilityFlagオペレータ
SetLock SymbolName TaggedParameters UnSetLock

プロパティ

AllImageClips Application BranchFlagオペレータ Capabilitiesオペレータ
Categories EvaluationID Familiesオペレータ FullNameオペレータ
Help HierarchicalEvaluationID ICEAttributes ImageClips
LockLevelオペレータ LockMastersオペレータ LockTypeオペレータ Model
Nameオペレータ NestedObjects ObjectID Origin
OriginPath OutputType Owners PPGLayoutオペレータ
Parametersオペレータ Parent Parent3DObject ProgID
Properties Root Selectedオペレータ ShaderDefオペレータ
ShaderType Shaders TextureLayers Typeオペレータ

1. VBScript の例

'
'       This example shows how to access the shader on an object
'
NewScene , false
dim root, grid
set root = ActiveProject.ActiveScene.Root
set grid = root.AddGeometry("Grid", "MeshSurface")
'Create a Lambert shader
grid.AddMaterial "Lambert" 
'Access the new Shader
LogMessage "Shader name:" & grid.Material.Shaders(0).Name

2. VBScript の例

'
'       This example shows how to recursively search a render tree
'
'       It shows how to access Shaders via the Source property of a Parameter
'       It also shows how to use XSICollection object to accumulate a list of objects
'
'       Note: to find ImageClips the Material.ImageClips property can be used rather
'       a recursive scan like this.  And the FindObjects command can be used to find
'       all shaders of a particular type.
'
set oObj = BuildDemoScene                       ' Create a little sample render tree
FindShaders(oObj)                                       ' Search the scene to find and log shaders
' ---------------------------------------------------
' Expected results:
' INFO : Skipping Sources.Materials.DefaultLib.Material.Phong
' INFO : SUMMARY: Searched 2 shader(s)
' INFO : SHADERS SEARCHED:
' INFO : Sources.Materials.DefaultLib.Material.Phong
' INFO : Sources.Materials.DefaultLib.Material.Lambert
' ---------------------------------------------------
' This is the actual code doing the searching
sub FindShaders( in_oObj )
        dim oShaderList, oImageClipList
        set oShaderList = CreateObject("XSI.Collection")
        oShaderList.Unique = true
        ' We expect the input object to be a "SceneItem" object
        set oMat = in_oObj.Material
        ' Although not actually a shader, we start searching
        ' for shaders from the parameters of the material
        SearchShader oMat, oShaderList
        Application.LogMessage "SUMMARY: Searched " & oShaderList.Count & " shader(s)"
        if ( oShaderList.Count > 0 ) then
                Application.LogMessage "SHADERS SEARCHED:"
                for each oShader in oShaderList
                        Application.LogMessage oShader.Fullname
                next                            
        end if
end sub
' Recursively search any connected shaders
' Each shader is visited only once
sub SearchShader( in_oShader, io_oVisitedShaderList)
        for each oParam in in_oShader.Parameters
                if typename( oParam.Source ) = "Shader" then
                        if ( NOT IsShaderInList(oParam.Source, io_oVisitedShaderList) ) then
                                io_oVisitedShaderList.Add(oParam.Source)
                                ' Recursively search this shader
                                SearchShader oParam.Source, io_oVisitedShaderList 
                        end if 
                end if
        next
end sub
' Determines if a shader is already in an XSICollection
function IsShaderInList( oShader, io_oVisitedShaderList )
        for each oVisitedShader in io_oVisitedShaderList        
                if (oVisitedShader.FullName = oShader.FullName) then
                        Application.LogMessage "Skipping " & oShader.FullName
                        IsShaderInList = true
                        exit function
                end if
        next
        IsShaderInList = false 
end function
' ---------------------------------------------------
' Create a little sample render tree
' It has no interesting visual appearance but is a render tree with
' various shaders and two images so that we can demonstrate the 
' FindImageClips routine
'
' Return value is the X3DObject
function BuildDemoScene
        ImageFile1 = XSIUtils.BuildPath(_
                Application.InstallationPath(siFactoryPath), _
                "Data", "XSI_SAMPLES", "Pictures", "jaiqua_face.jpg" )                  
        ImageFile2 = XSIUtils.BuildPath(_ 
                Application.InstallationPath(siFactoryPath), _
                "Data", "XSI_SAMPLES", "Pictures", "ehair_08.jpg" )                     
        NewScene , false
        set oObj = ActiveSceneRoot.AddGeometry("Sphere", "MeshSurface")
        oObj.AddMaterial "Phong" 
        dim oPhongShader, oAmbientParam, oDiffuseParam, oShinyParam
        set oPhongShader = oObj.Material.Shaders(0)
        set oAmbientParam = oPhongShader.Parameters("ambient")
        set oDiffuseParam = oPhongShader.Parameters("diffuse")  
        set oShinyParam = oPhongShader.Parameters("shiny")      
        dim oImageClip1, oImageClip2
        SICreateImageClip ImageFile1, ,oImageClip1      
        SICreateImageClip ImageFile2, ,oImageClip2
        dim oImageNode1,oImageNode2
        set oImageNode1 = oAmbientParam.connectfrompreset("Image", siTextureShaderFamily)
        oDiffuseParam.Connect(oImageNode1)      
        oImageNode1.Parameters("tex").Connect(oImageClip1)
        set oImageNode2 = oShinyParam.connectfrompreset("Image", siTextureShaderFamily)
        oImageNode2.Parameters("tex").Connect(oImageClip2)
        ' Commands can also be used to build a render tree
        CreateShaderFromPreset "Shaders\Material\Lambert.Preset", "Sources.Materials.DefaultLib.Material"
        SIConnectShaderToCnxPoint "Sources.Materials.DefaultLib.Material.Lambert", oObj.Material & ".Photon"
        ' Return the sphere
        set BuildDemoScene = oObj
end function

3. JScript の例

/*
        This example lists all installed shaders with their ProgId and OutputType, 
        plus all texturable parameters and their shader input type.
*/
var re = / /g;
var strShaderNames = Dictionary.info("",siShaderFamily).replace(re,"");
var aShaders = strShaderNames.split(",");
XSIUtils.QuickSort( aShaders );
var colitem = XSIFactory.CreateObject("XSI.CollectionItem");
var cShaders = 0;
for ( var i = 0; i < aShaders.length; i++ )
{
        var shader = null;
        var progid = "Softimage." + aShaders[i];
        if ( progid == "Softimage.TraversalCallback" ) continue;
        try {
                shader = XSIFactory.CreateObject( progid );
        } catch (e) {
                logmessage( "Error: can't create shader : " + progid );
                continue;
        }
        cShaders++;
        logmessage( progid + " " + ShaderParameterTypeAsText(shader.OutputType) );
        var params = shader.parameters;
        for ( var j = 0; j < params.count; j++ )
        {
                var param = shader.parameters(j);
                if ( param.capabilities & siTexturable )                                    
                        logmessage( "\t" + param.name + " " + ShaderParameterTypeAsText(shader.GetShaderInputType(param.scriptname)));
        }
}
logmessage( "Shaders found = " + cShaders );
function ShaderParameterTypeAsText(type)
{
        switch (type)
        {
                case siUnknownParameterType : return "siUnknownParameterType";                  
                case siBooleanParameterType : return "siBooleanParameterType";                  
                case siColorParameterType : return "siColorParameterType";                      
                case siDataParameterType : return "siDataParameterType";                        
                case siIntegerParameterType : return "siIntegerParameterType";                  
                case siLensParameterType : return "siLensParameterType";                        
                case siLightParameterType : return "siLightParameterType";                      
                case siMaterialParameterType : return "siMaterialParameterType";                        
                case siMatrixParameterType : return "siMatrixParameterType";                    
                case siModelParameterType : return "siModelParameterType";                      
                case siRealTimeParameterType : return "siRealTimeParameterType";                        
                case siReferenceParameterType : return "siReferenceParameterType";                      
                case siScalarParameterType : return "siScalarParameterType";                    
                case siShaderParameterType : return "siShaderParameterType";                    
                case siStringParameterType : return "siStringParameterType";                    
                case siStructParameterType : return "siStructParameterType";                    
                case siTextureParameterType : return "siTextureParameterType";                  
                case siTextureSpaceParameterType : return "siTextureSpaceParameterType";                        
                case siVectorParameterType : return "siVectorParameterType";                    
                default: return type;
        }
}
//

関連項目

Material.Shaders Light.Shaders Camera.Shaders ImageClip Parameter.Source Texture TextureLayer